<%@ page import="java.util.Map" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="Business.Music" %>
<%@ page import="java.util.List" %>
<%@ page import="Business.FinalAll" %>
<%@ page contentType="text/html;charset=UTF-8"%>
<%
    Map<String , Object> cookies = Business.Cookie.getCookieList(request.getCookies());
    Object cookieObj = cookies.get("cookie");
    Object openidObj = request.getAttribute("openid");
    Object contentObj = request.getAttribute("content");
    Object pageObj = request.getAttribute("page");
    boolean ObjErr = cookieObj == null || openidObj == null || contentObj == null || pageObj == null;
    if (ObjErr){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errMsg","参数异常！");
        out.println(jsonObject);
        return;
    }
    String cookie = cookieObj.toString();
    String openid = openidObj.toString();
    String content = contentObj.toString();
    String pagee = pageObj.toString();
    boolean strErr = cookie.length() <= 0 || openid.length() <= 0 || content.length() <= 0 || pagee.length() <= 0;
    if (strErr){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errMsg","参数异常！2");
        out.println(jsonObject);
        return;
    }//参数检查正确
    Map<String , Object> userinfo = Mysql.Query.getUser(openid);
    if (userinfo == null){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errMsg","用户状态异常！");
        out.println(jsonObject);
        return;
    }
    String mysqlCookie = userinfo.get("cookie").toString();
    if (!cookie.equals(mysqlCookie)){//不相同
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errMsg","用户状态异常！2");
        out.println(jsonObject);
        return;
    }//cookie检查完成
    List<Object> musiscs= Music.search(content , pagee);
    Business.Cookie.removeCookieAll(request.getCookies() , response);//清除所有cookie
    Cookie cookie1 = new Cookie("cookie",cookie);
    cookie1.setMaxAge(60 * 60 * 24 * FinalAll.OutTimeCookieDay);
    cookie1.setPath("/");
    response.addCookie(cookie1);//返回cookie
    JSONObject reJson = new JSONObject();
    reJson.put("errMsg",0);
    reJson.put("offset", pagee);
    reJson.put("result",musiscs);
    out.println(reJson);
%>